
goog.provide('esn.dao.StrainedFriendSurveyDao');

goog.require('esn.dao.BaseDao');


/**
 * @param {esn.model.StrainedFriendSurveyModel} model
 * @constructor
 */
esn.dao.StrainedFriendSurveyDao = function(model, surveyCient,
    opt_throttleTime) {
  goog.base(this, opt_throttleTime);

  this.surveyClient_ = surveyCient;

  this.model_ = model;
};
goog.inherits(esn.dao.StrainedFriendSurveyDao, esn.dao.BaseDao);

/** @inheritDoc */
esn.dao.StrainedFriendSurveyDao.prototype.getModel = function() {
  return this.model_;
};

/** @inheritDoc */
esn.dao.StrainedFriendSurveyDao.prototype.saveInternal = function(callback) {
  this.surveyClient_.updateStrainedFriendSurvey(
      this.model_,
      goog.bind(this.saveInternalResponse_, this, callback));
};

esn.dao.StrainedFriendSurveyDao.prototype.saveInternalResponse_ = function(
    callback, response) {
  if (!response.hasError()) {
    this.model_.mergeFrom(response.getData());
  } else {
    window.console.log(response.getError().getInternalMessage());
  }
  callback(response);
};

/** @inheritDoc */
esn.dao.StrainedFriendSurveyDao.prototype.removeInternal = function(callback) {
  if (this.model_.getId()) {
    this.surveyClient_.deleteStrainedFriendSurvey(
        this.model_.getId(),
        goog.bind(this.removeInternalResponse_, this, callback));
  } else {
    // This model doesn't have an ID which means it was never saved. Therefore,
    // there's no need to delete it.
    this.model_ = {};
    callback(new esn.client.Response());
  }
};

esn.dao.StrainedFriendSurveyDao.prototype.removeInternalResponse_ = function(
    callback, response) {
  if (response.hasError()) {
    window.console.log(response.getError().getInternalMessage());
  }
  callback(response);
};
